<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Illuminate\Support\Facades\Cache;


class User extends Authenticatable
{
    use HasFactory, SoftDeletes, Notifiable;

    const STATUS_NORMAL = 'normal';
    const STATUS_FORZEN = 'forzen';

    public static $statusMap = [
        self::STATUS_NORMAL => '正常',
        self::STATUS_FORZEN => '冻结',
    ];

    /**
     * 记住我字段名称
     *
     * @var string
     */
    protected $rememberTokenName = 'user_remember_token';

    /**
     * @var array
     */
    protected $fillable = [
        'username', 'phone', 'email', 'password', 'avatar', 'email_verified_at', 'status'
    ];

    /**
     * Get the token value for the "remember me" session.
     *
     * @return string|null
     */
    public function getRememberToken()
    {
        return Cache::get($this->getRememberTokenName(), '');
    }

    /**
     * Set the token value for the "remember me" session.
     *
     * @param  string  $value
     * @return void
     */
    public function setRememberToken($value)
    {
        Cache::put($this->getRememberTokenName(), $value, 86400 * 3);
    }

    /**
     * Get the column name for the "remember me" token.
     *
     * @return string
     */
    public function getRememberTokenName()
    {
        return $this->rememberTokenName . ':' . $this->getKeyName();
    }


    public function cashInfo()
    {
        return $this->hasOne(CashInfo::class);
    }
}
